home *** CD-ROM | disk | FTP | other *** search
- Path: svnews.ubinet.ubs.com!ubszh!ian.johnston@ubs.com
- From: ian.johnston@ubs.com (Ian Johnston (by ubsswop))
- Newsgroups: comp.lang.c++
- Subject: Re: Copy constructor
- Date: 12 Apr 1996 09:13:16 GMT
- Organization: UBS
- Distribution: world
- Message-ID: <4kl6rc$bpm@ubszh.fh.zh.ubs.com>
- References: <4kjudi$2qj0@holly.ACNS.ColoState.EDU>
- NNTP-Posting-Host: nol2179.fh.zh.ubs.com
-
- In article <4kjudi$2qj0@holly.ACNS.ColoState.EDU>, corbyh@holly.ACNS.ColoState.EDU (Corby S. Hudnall) writes:
- |> Hi all, I'm having some trouble figuring out how to do a copy
- |> constructor. Here's what I thought was suppose to work:
- |>
- |> header file----
- |> class ABC
- |> {
- |> private:
- |> int AnInt;
- |>
- |> public:
- |> ABC():AnInt(5) {} // Default Constructor
- |> ~ABC() {} // Default Destructor
- |> ABC(const ABC&); // Copy constructor
- |> }
- |>
- |> ABC::ABC(const ABC& NewABC)
- |> {
- |> this->AnInt = NewABC->AnInt;
- |> }
- |>
- |> Unfortunatly, I can't get this to work right. I get weird messages from
- |> the compiler complaining about not being able to use a class definition
- |> as an argument. This was using xlC under IBM Aix. Any suggestions are
- |> greatly appreciated. Thanks.
-
-
- Try:
-
- ABC::ABC(const ABC& NewABC)
- {
- this->AnInt = NewABC.AnInt;
- }
-
-
- (The "this->" part is optional.)
-
- Ian
-
-